<?php

/**
 * 消息模型
 */

namespace app\api\model;


use PDOStatement;
use think\Collection;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\Model;

class Message extends Model {

    /**
     * 消息主页
     * @param $params
     * @return array|PDOStatement|string|Collection
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public static function get_message($params) {
        //智能选房最新消息
        $MessageUserHouse = MessageUserHouse::getNew($params['user_id'], 'title,itime');
        if (!empty($MessageUserHouse)) {
            $notReadnum = MessageUserHouse::getNotread($params['user_id']);
            $MessageUserHouse['name'] = '智能选房';
            $MessageUserHouse['message'] = $MessageUserHouse['title'];
            $MessageUserHouse['itime'] = date('m月d日H:i', $MessageUserHouse['itime']);
            $MessageUserHouse['notReadnum'] = $notReadnum;
            unset($MessageUserHouse['title']);
        } else {
            $MessageUserHouse['name'] = '智能选房';
            $MessageUserHouse['message'] = '';
            $MessageUserHouse['itime'] = '';
            $MessageUserHouse['notReadnum'] = 0;
        }
        //系统通知最新消息
        $MessageUserSystem = MessageUserSystem::getNew($params['user_id'], 'title,itime');
        if (!empty($MessageUserSystem)) {
            $notReadnum = MessageUserSystem::getNotread($params['user_id']);
            $MessageUserSystem['name'] = '系统消息';
            $MessageUserSystem['message'] = $MessageUserSystem['title'];
            $MessageUserSystem['itime'] = date('m月d日H:i', $MessageUserSystem['itime']);
            $MessageUserSystem['notReadnum'] = $notReadnum;
            unset($MessageUserSystem['title']);
        } else {
            $MessageUserSystem['name'] = '系统消息';
            $MessageUserSystem['message'] = '';
            $MessageUserSystem['itime'] = '';
            $MessageUserSystem['notReadnum'] = 0;
        }
        $data = ['messageUserHouse' => $MessageUserHouse, 'messageUserSystem' => $MessageUserSystem];
        return $data;
    }

}
